package com.example.demo.controller;

import com.example.demo.pojo.User;
import com.example.demo.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class UserController {
    private static Logger logger = Logger.getLogger(UserController.class);

    @Autowired
    UserService userService;

    @RequestMapping("/add")
    @ResponseBody
    public String addUser(User user){

        int result=userService.add(user);

        if (result==0){

            return "新增成功";
        }else {

            return "新增失败";
        }
    }

    @RequestMapping("/update")
    @ResponseBody
    public String update(User user){

       int result= userService.update(user);

        if (result==0){

            return "更新成功";
        }else {

            return "更新失败";
        }
    }

    @RequestMapping("/del")
    @ResponseBody
    public String del(User user){

        int result= userService.del(user);

        if (result==0){

            return "删除成功";
        }else {

            return "删除失败";
        }
    }
}
